
import { MyProjectManager } from "@/MyProjectManager";
import { Destroyable, react, JsonValue, track, bind } from "xbsj-xe2/dist-node/xe2-base-utils";
import { camera } from "../dataTypes";
import { ESImageLabel } from "esobjs-xe2-plugin/dist-node/esobjs-xe2-plugin-main";
export class CameraManager extends Destroyable {
    // 存储三维对象
    public map = new Map<string, ESImageLabel>()
    // 存储摄像头原始数据
    public data: camera[] = []
    // 分组
    public cameraGroups = new Map<string, any>()
    constructor(private myProjectManager: MyProjectManager) {
        super();
        this.myProjectManager = myProjectManager
    }

    /**
     * 初始化摄像头
     * @param data 
     */
    init(data: camera[]) {
        this.destroyAll()
        data.forEach((element: { name: string, id: string, position: [number, number, number], extras: string }) => {
            this.createCamera(element)
        });
    }
    /**
     * 创建摄像头
     * @param element 
     * @returns 
     */
    createCamera(element: camera) {
        const { id, name, position, extras } = element
        let groupCamera = this.cameraGroups.get(extras)
        if (groupCamera) {
            groupCamera = this.cameraGroups.set(extras, { cameras: [] })
        }
        // 创建摄像头
        const e = this.myProjectManager.createSceneObject(ESImageLabel, id)
        if (!e) return
        // 设置名称
        e.name = name
        // 设置位置
        e.position = position
        // 尺寸设置
        e.sizeByContent = false
        e.size = [40, 50]
        // 拾取事件
        e.widgetEvent.don((info) => {
            switch (info.type) {
                case 'mouseEnter':
                    break;
                case 'mouseLeave':
                    break;
                case 'leftClick':
                    alert(e.name + "被左键点击了!")
                    break;
                case 'rightClick':
                    alert(e.name + "被右键点击了!")
                    break;
                default:
                    break;
            }
        })
        this.map.set(id, e)
        this.data.push(element)

    }

    /**
     * 销毁所有摄像头
     */
    destroyAll() {
        this.map.forEach((value, key) => {
            this.myProjectManager.destroySceneObject(value)
            this.map.delete(key)
        })
        this.data.length = 0
    }
}